<?php

namespace App\Admin\Controllers;

use App\email;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class EmailController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'App\email';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new email());

        $grid->filter(function($filter){

            // 去掉默认的id过滤器
            $filter->disableIdFilter();

            // 在这里添加字段过滤器
            $filter->like('Email', '邮箱');

        });

        $grid->column('Email', __('邮箱'))->display(function($text) {
            return str_limit($text, 12, '...');
        });
        $grid->column('EmailPwd', __('邮箱密码'))->display(function($text) {
            return str_limit($text, 12, '...');
        });
        $grid->column('EmailPhone', __('邮箱手机'));
        $grid->column('RegistrationDate', __('注册时间'));
        $grid->column('RegistrationIP', __('注册IP地'));
        $grid->column('Question1', __('注册问题1'))->display(function($text) {
            return str_limit($text, 12, '...');
        });
        $grid->column('Answer1', __('答案1'));
        $grid->column('Question2', __('注册问题2'))->display(function($text) {
            return str_limit($text, 12, '...');
        });
        $grid->column('Answer2', __('答案2'));
        $grid->column('Question3', __('注册问题3'))->display(function($text) {
            return str_limit($text, 12, '...');
        });
        $grid->column('Answer3', __('答案3'));



        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(email::findOrFail($id));


        $show->field('Email', __('邮箱'));
        $show->field('EmailPwd', __('邮箱密码'));
        $show->field('EmailPhone', __('邮箱手机'));
        $show->field('RegistrationDate', __('注册时间'));
        $show->field('RegistrationIP', __('注册IP地'));
        $show->field('Question1', __('注册问题1'));
        $show->field('Answer1', __('答案1'));
        $show->field('Question2', __('注册问题2'));
        $show->field('Answer2', __('答案2'));
        $show->field('Question3', __('注册问题3'));
        $show->field('Answer3', __('答案3'));


        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new email());


        $form->email('Email', __('邮箱'));
        $form->password('EmailPwd', __('邮箱密码'));
        $form->mobile('EmailPhone', __('邮箱手机'));
        $form->datetime('RegistrationDate', __('注册时间'));
        $form->text('RegistrationIP', __('注册IP地'));
        $form->text('Question1', __('注册问题1'));
        $form->text('Answer1', __('答案1'));
        $form->text('Question2', __('注册问题2'));
        $form->text('Answer2', __('答案2'));
        $form->text('Question3', __('注册问题3'));
        $form->text('Answer3', __('答案3'));

        return $form;
    }
}
